package com.ccs.demo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RequestMapping("/request")
@RestController
public class RequestController1 {
    @RequestMapping("/r1")
    public String r1(String name){
        return name;
    }

    @RequestMapping("/r2")
    public int r2(int age){
        return age;
    }

    @RequestMapping("/r3")
    public int r3(int sex){
        return sex;
    }

    @RequestMapping("/r4")
    public String r4(String name,int age,int sex){
        return "name=" + name +" age="+age+" sex="+sex;
    }

    @RequestMapping("/r5")
    public String r5(Person person){
        return person.toString();
    }

    // 重命名
    @RequestMapping("/r6")
    public String r6(@RequestParam("name") String n,@RequestParam(value = "age",required=false,defaultValue = "19") int a){
        return "name="+ n + " age=" + a ;
    }

    @RequestMapping("/r7")
    public String r7(String[] name){
        return Arrays.toString(name);
    }

    @RequestMapping("/r8")
    public String r8(@RequestParam List<String> names){
        return " 结果："+ names;
    }

    @RequestMapping()
    public String r9(@PathVariable Integer id,@PathVariable String username){
        return id+" "+username;
    }

    @RequestMapping("/r10/{articleId}")
    public String r10(@PathVariable Integer articleId){
        return "接收到参数 articleId: "+ articleId;
    }

    @RequestMapping ("/r10/{articleId}/{type}")
    public String r11(@PathVariable Integer articleId,@PathVariable String type){
        return "articleId:" + articleId + "type: "+ type;
    }

    @RequestMapping("r12")
    public String r12(@RequestParam MultipartFile file){
        System.out.println(file.getName());
        return "接收文件成功" + "  file.getName:"+ file.getName()
                + "  file.getOriginalFilename:" +file.getOriginalFilename()
                + "file.getOriginalFilename: " +  file.getContentType();
    }

}
